/*
ont-space - The ontology-based resource metadata repository
Copyright (c) 2006-2008, Information Eng. Research Unit - Univ. of Alcalá
http://www.cc.uah.es/ie
This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at your option)
any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.
You should have received a copy of the GNU Lesser General Public License along
with this library; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */
package org.ontspace.util.translator.lom2owl.owl;

import org.ieee.ltsc.lom.LOM;
import org.ieee.ltsc.lom.LOMUtil;

import java.io.*;
import com.hp.hpl.jena.ontology.*;
import com.hp.hpl.jena.rdf.model.RDFNode;

/**
 * Translates direct-translation elements. 
 */
public class DirectTranslator extends ElementTranslatorImpl {

    /** Creates a new instance of DirectTranslator */
    private String category =
            new String();
    private String attributeName =
            new String();
    private String element =
            new String();

    public DirectTranslator(String elementCategory, String elementElement,
            String elementAttribute) {

        this.category =
                elementCategory;
        this.attributeName =
                elementAttribute;
        this.element =
                elementElement;
    }

    /**
     * This method translates direct-translation elements.      
     * The translation does not required any new element.      
     * @param lom The metadata record
     * @param ont The ontology
     * @param inst The instance of learning Object
     * @param nsName The namespace
     * @param errorWriter The error file
     */
    public void apply(LOM lom, OntModel ont, Individual inst, String nsName,
            PrintWriter errorWriter) {
        // 1) Get the information from lom xml file


        if (category.equals("Technical")) {
            //4.2 size
            if (element.equals("Size")) {

                String sizeLOM =
                        LOMUtil.getString(LOMUtil.getTechnicalSize(lom));
                DatatypeProperty sizeProperty =
                        ont.getDatatypeProperty(nsName +
                        "#hasSize");
                if (sizeLOM != null) {
                    RDFNode sizeValue =
                            ont.createTypedLiteral(sizeLOM);
                    inst.setPropertyValue(sizeProperty, sizeValue);
                }
            } //4.3 location
            else if (element.equals("Location")) {

                int i =
                        0;
                DatatypeProperty locatedProperty =
                        ont.getDatatypeProperty(nsName + "#isLocated");
                while (LOMUtil.getTechnicalLocation(lom, i) != null) {
                    String locationLOM =
                            LOMUtil.getString(LOMUtil.getTechnicalLocation(lom,
                            i));
                    if (locationLOM != null) {
                        RDFNode locationValue =
                                ont.createTypedLiteral(locationLOM);
                        inst.addProperty(locatedProperty, locationValue);
                    }
                    i++;
                }
            }
        }

    }
}
